package com.bwie.controller;

import com.baomidou.mybatisplus.annotation.TableField;
import com.bwie.config.MyNacosConfig;
import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginAdminVo;
import com.bwie.vo.LoginForm;
import com.bwie.vo.PageInfoVo;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @description :
 * @Author QiHainan
 * @Create 2025/4/20 18:47
 * @Version 1.0
 */
@RestController
@RequestMapping("/user/index")
@RefreshScope
public class IndexController {
    @Autowired
    TbUserService tbUserService;
    @Autowired
    MyNacosConfig myNacosConfig;
    @Value("${site.className}")
    private String className;

    /**
     * 根据id查询用户信息
     * @param userId
     * @return
     */
    @PostMapping("/getUserByUserId/{userId}")
    public R getUserByUserId(@PathVariable("userId") Integer userId){
        return tbUserService.getUserByUserId(userId);
    }

    /**
     * 登录
     * @param loginAdminVo
     * @return
     */
    @PostMapping("/login")
    public R login(@RequestBody @Validated LoginAdminVo loginAdminVo){
        return tbUserService.login(loginAdminVo);
    }

    /**
     * 手机号登录
     * @param loginForm
     * @return
     */
    @PostMapping("/loginByMobile")
    public R loginByMobile(@RequestBody @Validated LoginForm loginForm){
        return tbUserService.loginMobile(loginForm);
    }

    /**
     * 发送验证码
     * @param mobile
     * @return
     */
    @PostMapping("/sendCode/{mobile}")
    public R sendCode (@PathVariable("mobile") String mobile){
        return tbUserService.sendCode(mobile);
    }

    /**
     * 用户注册
     * @param tbUser
     * @return
     */
    @PostMapping("/addUser")
    public R addUser(@RequestBody @Validated TbUser tbUser){
        return tbUserService.addUser(tbUser);
    }

    /**
     * 用户分页列表
     * @param pageInfoVo
     * @return
     */
    @PostMapping("/getUserPage")
    public R getUserPage(@RequestBody PageInfoVo pageInfoVo){
        return tbUserService.getUserPage(pageInfoVo);
    }

    /**
     * 第一种：获取配置文件信息
     * @return
     */
    @PostMapping("/getNacos1")
    public R getNacos1(){
        System.out.println("myNaocs:"+myNacosConfig.getClassName());
        return R.OK(myNacosConfig.getClassName());
    }

    /**
     * 第二种：获取配置文件信息
     * @return
     */
    @PostMapping("/getNacos2")
    public R getNacos2(){
        System.out.println("nacos:"+className);
        return R.OK(className);
    }

    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/loadImage")
    public R loadImage(@RequestPart("file") MultipartFile file){
        return tbUserService.loadImage(file);
    }

    /**
     * 审核用户
     * @param tbUser
     * @return
     */
    @PostMapping("/checkUser")
    public R checkUser(@RequestBody TbUser tbUser){
        return tbUserService.checkUser(tbUser);
    }

    /**
     * 修改用户
     * @param tbUser
     * @return
     */
    @PostMapping("/updateUser")
    public R updateUser(@RequestBody TbUser tbUser){
        return tbUserService.updateUser(tbUser);
    }

    /**
     * 根据id删除商户
     * @param userId
     * @return
     */
    @PostMapping("/deleteByUserId/{userId}")
    public R deleteByUserId(@PathVariable("userId") Integer userId){
        return  tbUserService.deleteByUserId(userId);
    }

    /**
     * 批量删除商户
     * @param ids
     * @return
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<TbUser> ids){
        return tbUserService.deleteBatch(ids);
    }
}
